using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

using Material.Object;
using Material.Entity;


namespace Material.App
{
    public partial class FrmFindPenjBarang : Form
    {
        private TblTransPenjBarangHDR   tblTransPenjBarangHDR;
        private TblTransPenjBarangHDREntity tblTransPenjBarangHDREntity;
        private string connStr = ConfigurationManager.ConnectionStrings["dbconnection"].ToString();
        public string idBarang = string.Empty;

        public FrmFindPenjBarang()
        {
            InitializeComponent();
            BindGrid();
         

            dataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque;
            dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
            dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

            dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Green;
            dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Yellow;

           

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
          
        }

        private void FrmFindBarang_Load(object sender, EventArgs e)
        {

        }

        private void BindGrid()
        {
            tblTransPenjBarangHDREntity = new TblTransPenjBarangHDREntity(connStr);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = tblTransPenjBarangHDREntity.GetFindDataAll().Tables[0];
        }

        private void BindGrid(string parameter,string value)
        {
            tblTransPenjBarangHDREntity = new TblTransPenjBarangHDREntity(connStr);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = tblTransPenjBarangHDREntity.GetFindDataAll(parameter,value).Tables[0];
        }

        private void cbListParameter_SelectedIndexChanged(object sender, EventArgs e)
        {
            //txtFind.Text = string.Empty;
            //if (cbListParameter.SelectedIndex == 0)
            //{
            //    txtFind.Visible = false;
            //    btnFind.Visible = false;
            //    //cbListFind.Visible = false;

            //    tglAkhir.Visible = false;
            //    tglMulai.Visible = false;
            //    lblTgl.Visible = false;
            //    BindGrid();
            //}
            //else if (cbListParameter.SelectedIndex == 1)
            //{
            //    //cbListFind.Visible = true;
            //    txtFind.Visible = true;
            //    btnFind.Visible = true;
            //    //cbListFind.Visible = false;
            //    tglAkhir.Visible = false;
            //    tglMulai.Visible = false;
            //    lblTgl.Visible = false;

            //    txtFind.Focus();
            //}
            //else if (cbListParameter.SelectedIndex == 2)
            //{
            //    //cbListFind.Visible = true;
            //    txtFind.Visible = false;
            //    btnFind.Visible = true;

            //    tglAkhir.Visible = true;
            //    tglMulai.Visible = true;
            //    lblTgl.Visible = true;



                
            //}
           
            
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            
           BindGrid("TglJual", tglMulai.Value.ToString("dd/MM/yyy") + "|" + tglAkhir.Value.ToString("dd/MM/yyyy"));

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {
            
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.RowIndex > -1) && (e.ColumnIndex > -1))
            {

                switch (e.ColumnIndex)
                {
                    case 0:
                        //FrmPenjBarangDTL.IdTransDTL = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                        //FrmPenjBarangDTL.IdBarang = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
                        FrmPenjBarangHRD.idHDR = Convert.ToInt32((dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()));
                        this.Close();
                        break;
                }
            }
        }

    }
}